<?php

namespace app\api\controller;

use app\common\controller\Api;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;

/**
 * 员工控制器
 * @package app\index\controller
 */
class Test extends Auth
{
    public $noNeedLogin = ['*'];

    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main(){
        $client = self::createClient("LTAI2UzMicjqIxKt", "OPeXmeSSDsA5dIddsQchvItYoT8V9x");
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => "18039920816",
            "signName" => "萌小呆",
            "templateCode" => "SMS_204750968",
            "templateParam" => "{\"code\":\"123456\"}"
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $client->sendSms($sendSmsRequest);
    }

    //性别 1 男 2 女
    public function index(){
        $res1 = $this->string2bytes('0500842CB9');
        $data = implode('',$res1);
        dump($data);die;
    }


    public function string2bytes($str){
        $bytes=array();
        for ($i=0; $i < strlen($str); $i++) {
            $tmp=substr($str, $i,1);
            $bytes[]=bin2hex($tmp);
        }
        $data = implode('',$bytes);
        return '02'.$data.'03';
    }

}
